package com.example.research.service;

import com.example.research.model.Research;
import com.example.research.repository.ResearchRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

@Service
public class ResearchService {
    @Autowired
    private ResearchRepository researchRepository;

    public List<Research> findAll() {
        return researchRepository.findAll();
    }

    public Research save(Research research) {
        return researchRepository.save(research);
    }

    public void delete(Integer id) {
        researchRepository.deleteById(id);
    }

    // 修改后的方法，返回 Optional<Research>
    public Optional<Research> findById(Integer id) {
        return researchRepository.findById(id);
    }

    public List<Research> findByTeacher(Integer teacherId) {
        return researchRepository.findByTeacherTeacherId(teacherId);
    }

    public List<Research> findByType(Integer typeId) {
        return researchRepository.findByResearchTypeTypeId(typeId);
    }

    public List<Research> search(String keyword) {
        return researchRepository.search(keyword);
    }

    public Long countByTeacherAndType(Integer teacherId, Integer typeId) {
        return researchRepository.countByTeacherAndType(teacherId, typeId);
    }


}
